﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using Utility;
namespace Service
{
    /// <summary>
    /// 功能：HW_ChangeSchool类数据访问
    /// 创建人：Wilson
    /// 创建时间：2013-1-30   
    /// </summary>
    public class HW_ChangeSchoolService : IDisposable
    {
        #region 公共
        private System.ComponentModel.Component component = new System.ComponentModel.Component();

        private bool disposed = false;

        ~HW_ChangeSchoolService()
        {
            Dispose(false);
        }

        #endregion

        #region IDisposable 成员

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {

                if (disposing)
                {

                    component.Dispose();
                }

                disposed = true;

            }
        }
        #endregion
		#region##MapperHW_ChangeSchool
        public IList<HW_ChangeSchool> MapperList(SqlDataReader reader)
         {
            IList<HW_ChangeSchool> list = new List<HW_ChangeSchool>();
            HW_ChangeSchool obj=null;
            while (reader.Read())
            {
                obj = new HW_ChangeSchool();
                obj.ChangeId = (int)reader["ChangeId"];
                obj.OldStudentCode = (string)reader["OldStudentCode"];
                obj.NewStudentCode = (string)reader["NewStudentCode"];
                obj.ActiveDate = reader["ActiveDate"] as DateTime?;
                obj.OldSchoolCode = (string)reader["OldSchoolCode"];
                obj.NewSchoolCode = (string)reader["NewSchoolCode"];
                obj.Statute = (bool)reader["Statute"];
                obj.Version = (int)reader["Version"];
                list.Add(obj);
            }
            return list;
         }
        public HW_ChangeSchool Mapper(SqlDataReader reader)
         {
            HW_ChangeSchool obj=null;
            if (reader.Read())
            {
                obj = new HW_ChangeSchool();
                obj.ChangeId = (int)reader["ChangeId"];
                obj.OldStudentCode = (string)reader["OldStudentCode"];
                obj.NewStudentCode = (string)reader["NewStudentCode"];
                    obj.ActiveDate = reader["ActiveDate"] as DateTime?;
                obj.OldSchoolCode = (string)reader["OldSchoolCode"];
                obj.NewSchoolCode = (string)reader["NewSchoolCode"];
                obj.Statute = (bool)reader["Statute"];
                obj.Version = (int)reader["Version"];
            }
            return obj;
         }
        #endregion
        #region##通过主键ID得到HW_ChangeSchool
        /// <summary>
        /// 功能：通过ID得到HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
        public HW_ChangeSchool GetById(int changeid)
        {            
            string sql = "select * from HW_ChangeSchool where ChangeId = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            
            SqlDataReader reader=SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql,sp);
            return Mapper(reader);
        }
        #endregion
		
		#region##通过主键ID删除HW_ChangeSchool
        /// <summary>
        /// 功能：通过主键ID删除HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(int changeid)
		{
			int i = 0;
			string sql = "delete from HW_ChangeSchool where ChangeId = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            i= SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
			return i;
		}
        /// <summary>
        /// 功能：通过主键ID删除HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(SqlTransaction transaction,int changeid)
		{
			int i = 0;
			string sql = "delete from HW_ChangeSchool where ChangeId = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            i= SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
			return i;
		}
		#endregion			
		
        #region##添加HW_ChangeSchool
        /// <summary>
        /// 功能：添加HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(HW_ChangeSchool hw_changeschool)
        {
            int result = 0;
            string sql = "insert into HW_ChangeSchool(ChangeId,OldStudentCode,NewStudentCode,ActiveDate,OldSchoolCode,NewSchoolCode,Statute,Version) values(@ChangeId,@OldStudentCode,@NewStudentCode,@ActiveDate,@OldSchoolCode,@NewSchoolCode,@Statute,@Version)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@ChangeId",hw_changeschool.ChangeId),
				new SqlParameter("@OldStudentCode",hw_changeschool.OldStudentCode),
				new SqlParameter("@NewStudentCode",hw_changeschool.NewStudentCode),
				new SqlParameter("@ActiveDate",hw_changeschool.ActiveDate),
				new SqlParameter("@OldSchoolCode",hw_changeschool.OldSchoolCode),
				new SqlParameter("@NewSchoolCode",hw_changeschool.NewSchoolCode),
				new SqlParameter("@Statute",hw_changeschool.Statute),
				new SqlParameter("@Version",hw_changeschool.Version)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：添加HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(SqlTransaction transaction,HW_ChangeSchool hw_changeschool)
        {
            int result = 0;
            string sql = "insert into HW_ChangeSchool(ChangeId,OldStudentCode,NewStudentCode,ActiveDate,OldSchoolCode,NewSchoolCode,Statute,Version) values(@ChangeId,@OldStudentCode,@NewStudentCode,@ActiveDate,@OldSchoolCode,@NewSchoolCode,@Statute,@Version)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@ChangeId",hw_changeschool.ChangeId),
				new SqlParameter("@OldStudentCode",hw_changeschool.OldStudentCode),
				new SqlParameter("@NewStudentCode",hw_changeschool.NewStudentCode),
				new SqlParameter("@ActiveDate",hw_changeschool.ActiveDate),
				new SqlParameter("@OldSchoolCode",hw_changeschool.OldSchoolCode),
				new SqlParameter("@NewSchoolCode",hw_changeschool.NewSchoolCode),
				new SqlParameter("@Statute",hw_changeschool.Statute),
				new SqlParameter("@Version",hw_changeschool.Version)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##得到HW_ChangeSchool集合
		/// <summary>
        /// 功能：得到HW_ChangeSchool集合
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>       
        /// <returns></returns>
		public IList<HW_ChangeSchool> GetList()
		{
			string sql = "select * from HW_ChangeSchool";			
			SqlDataReader reader = SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql);
            return MapperList(reader);
		}
		#endregion
		
		#region##修改HW_ChangeSchool
        /// <summary>
        /// 功能：修改HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_ChangeSchool(HW_ChangeSchool hw_changeschool)
        {
            int result = 0;
            string sql = "update HW_ChangeSchool set ChangeId = @ChangeId,OldStudentCode = @OldStudentCode,NewStudentCode = @NewStudentCode,ActiveDate = @ActiveDate,OldSchoolCode = @OldSchoolCode,NewSchoolCode = @NewSchoolCode,Statute = @Statute,Version = @Version where ChangeId = @ChangeId";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@ChangeId",hw_changeschool.ChangeId),
				new SqlParameter("@OldStudentCode",hw_changeschool.OldStudentCode),
				new SqlParameter("@NewStudentCode",hw_changeschool.NewStudentCode),
				new SqlParameter("@ActiveDate",hw_changeschool.ActiveDate),
				new SqlParameter("@OldSchoolCode",hw_changeschool.OldSchoolCode),
				new SqlParameter("@NewSchoolCode",hw_changeschool.NewSchoolCode),
				new SqlParameter("@Statute",hw_changeschool.Statute),
				new SqlParameter("@Version",hw_changeschool.Version)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：修改HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_ChangeSchool(SqlTransaction transaction,HW_ChangeSchool hw_changeschool)
        {
            int result = 0;
            string sql = "update HW_ChangeSchool set ChangeId = @ChangeId,OldStudentCode = @OldStudentCode,NewStudentCode = @NewStudentCode,ActiveDate = @ActiveDate,OldSchoolCode = @OldSchoolCode,NewSchoolCode = @NewSchoolCode,Statute = @Statute,Version = @Version where ChangeId = @ChangeId";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@ChangeId",hw_changeschool.ChangeId),
				new SqlParameter("@OldStudentCode",hw_changeschool.OldStudentCode),
				new SqlParameter("@NewStudentCode",hw_changeschool.NewStudentCode),
				new SqlParameter("@ActiveDate",hw_changeschool.ActiveDate),
				new SqlParameter("@OldSchoolCode",hw_changeschool.OldSchoolCode),
				new SqlParameter("@NewSchoolCode",hw_changeschool.NewSchoolCode),
				new SqlParameter("@Statute",hw_changeschool.Statute),
				new SqlParameter("@Version",hw_changeschool.Version)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##统计HW_ChangeSchool
		/// <summary>
        /// 修改HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
		public int SelectCount()
		{
			int i = 0;
            string sql = "select count(*) from HW_ChangeSchool";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
		}
		/// <summary>
        /// 修改HW_ChangeSchool
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int SelectCountById()
        {
            int i=0;
            string sql="select count(ChangeId) from HW_ChangeSchool";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
        }
		#endregion
        #region##自定义HW_ChangeSchool
        #endregion
                
    }
}
